package com.safe.first.application.service;

import com.safe.first.application.dto.cmd.CreateOrderCmd;
import com.safe.first.common.service.AbstractService;
import com.safe.first.domain.order.factory.CompositeOrderFactory;
import com.safe.first.domain.order.model.Order;
import com.safe.first.domain.order.repo.OrderRepo;
import com.safe.first.domain.user.User;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author Mickey
 * @since 2022/5/22
 **/
@Service
@AllArgsConstructor
public class OrderAppService extends AbstractService {

    private final OrderRepo orderRepo;
    private final CompositeOrderFactory compositeOrderFactory;

    public Order create(CreateOrderCmd<?> createOrder, User user) {
        return creatorFor(orderRepo)
                .instance(() -> compositeOrderFactory.instance(createOrder.converter(), user))
                .call();
    }

}
